package frame.options.simulation.results.physicalNetworks.graphical;

import javax.swing.Icon;

import model.components.nodes.node.Node;
import model.components.nodes.node.PhysicalNode;
import model.components.nodes.node.PhysicalServer;
import org.apache.commons.collections15.Transformer;

public class PhysicalNodeIconTransformer implements Transformer< Node, Icon >
{
	@Override
	public Icon transform( Node node )
	{
		if( node.isSelected() )
			return node.getGreenIcon();
				
		if( node.getType().equals( Node.ROUTER_TYPE ) || node.getType().equals( Node.SWITCH_TYPE ) )
		{
			PhysicalNode physicalNode = (PhysicalNode) node;
			
			if( physicalNode.getAvailableCpu()    < physicalNode.getCpu()    * 0.2 || 
				physicalNode.getAvailableMemory() < physicalNode.getMemory() * 0.2  )
			    return physicalNode.getRedIcon();
			
			else if( physicalNode.getAvailableCpu()    < physicalNode.getCpu() || 
					 physicalNode.getAvailableMemory() < physicalNode.getMemory() )
				return physicalNode.getYellowIcon();
		}
		else if( node.getType().equals( Node.SERVER_TYPE ) )
		{
			PhysicalServer physicalServer = (PhysicalServer) node;
			
			if( physicalServer.getAvailableCpu()       < physicalServer.getCpu()       * 0.2 || 
				physicalServer.getAvailableMemory()    < physicalServer.getMemory()    * 0.2 ||
				physicalServer.getAvailableDiskSpace() < physicalServer.getDiskSpace() * 0.2 )
			    return physicalServer.getRedIcon();
			
			else if( physicalServer.getAvailableCpu()       < physicalServer.getCpu()       || 
					 physicalServer.getAvailableMemory()    < physicalServer.getMemory()    ||
					 physicalServer.getAvailableDiskSpace() < physicalServer.getDiskSpace() )
				return physicalServer.getYellowIcon();
		}
		
		return node.getGreyIcon(); 
	}

}
